package com.gvitz.transaction.fragments;


import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockFragment;
import com.gvitz.transaction.R;
import com.gvitz.transaction.database.gvitzDB;
import com.gvitz.transaction.models.transaction;
import com.gvitz.transaction.utils.TransItemAdapter;
 
public class TransactionsFragment extends SherlockFragment {
	
	
	ArrayList<transaction> mTrans = null;
	gvitzDB dbHelper= null;
	private View view;
	Activity act = getActivity();

	TransItemAdapter TransAdapter = null;

	
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
    	
       	
    	// Reciclar
    	 
    	if (view != null) {
    		 ViewGroup parent = (ViewGroup) view.getParent();
    		 if (parent != null)
    			 parent.removeView(view);
    	 	}
    	else
    	{
    		try {
       		
    		 view = inflater.inflate(R.layout.fragment_transactions, container, false);
       		 dbHelper = new gvitzDB(getActivity().getApplicationContext());
       		 mTrans= dbHelper.GetTransacciones();
       		 final ListView listView = (ListView) view.findViewById(R.id.list_transactions);   
       		    if ((mTrans==null)||(mTrans.size()==0)){
       		    	
       		    	listView.setVisibility(View.GONE);
       		        TextView l = (TextView) view.findViewById(R.id.noDataT); 
       		        l.setVisibility(View.VISIBLE);
       		    }
       		    else{

       		    	TransAdapter = new TransItemAdapter(getActivity().getApplicationContext(),android.R.id.list, mTrans,getActivity());
       		    	listView.setAdapter(TransAdapter); 
       		    	      		    	
       		    	}  
				
			} catch (Exception e) {
				// TODO: handle exception
			}
    	}
  
        return view;
    }
 
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        setUserVisibleHint(true);
    }
    
    

      
 
}